Skip to content

Fix paginate() to avoid redundant get_breads() queryset evaluation#668

Open
Kkt04 wants to merge 1 commit intowagtail:mainfrom
Kkt04:fix/paginate-args-redundant-queryset
Open

Fix paginate() to avoid redundant get_breads() queryset evaluation#668
Kkt04 wants to merge 1 commit intowagtail:mainfrom
Kkt04:fix/paginate-args-redundant-queryset

Conversation

@Kkt04
Copy link
Copy Markdown
Contributor

@Kkt04 Kkt04 commented Mar 18, 2026

Summary

Fixes #664

BreadsIndexPage.paginate() accepted *args but never used them. It was called in get_context() with self.get_breads() passed as an argument:

https://github.com/wagtail/bakerydemo/blob/63c1e81/bakerydemo/breads/models.py#L256-L257

But paginate() silently ignored the argument and called self.get_breads() internally again:

https://github.com/wagtail/bakerydemo/blob/63c1e81/bakerydemo/breads/models.py#L239-L245

This resulted in two queryset evaluations (two database queries) on every /breads/ page load — one wasted.

Changes

  • Replaced *args with explicit queryset=None parameter in paginate()
  • paginate() now uses the passed queryset or falls back to self.get_breads()
  • Updated call site in get_context() — no longer passes self.get_breads() as argument
  • get_breads() is now called only once per request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BreadsIndexPage.paginate() accepts *args but ignores them, causing redundant queryset evaluation

1 participant